<?php
/**
 * Class model that provides the base functionality to manage Projects data
 *
 * This class was defined following the indications of
 * {@link http://www.overzealous.com/dmz/index.html DMZ ORM}. So,
 * this manage inserts, updates and deletes sql operations, as well as fully
 * set of instructions that can be used to make queries. And much more
 *
 * @author Gonzalez Federico, Viera Leonel
 * @package Protoweb
 * @subpackage model
 */
class Project extends PwModel
{
    public $table      = "projects";
    public $model      = "project";
    public $has_many   = array("user","entity");
    public $has_one    = array();
    public $validation = array(
       "name" => array(
           "label" => "Name",
           "rules" => array("trim", "required")
        ),
       "description" => array(
           "label" => "Description",
           "rules" => array("trim")
        ),
       "slug" => array(
           "label" => "Key Name",
           "rules" => array("trim", "required", "unique", "alpha_numeric")
        )
    ); // $validation

    public function __construct($id = NULL) 
    {
       parent::__construct($id);
    }

    /**
     * Returns the base path of the generated's project files. As BASEPATH in codeigniter
     *
     * @return string
     */
    public function base_path()
    {
        return (dirname(BASEPATH) . '/projects/' . $this->slug . "/");
    }
  
    /**
     * Returns the base_url of the generated's project
     *
     * @return string
     */
    public function base_url()
    {
        return (base_url() . 'projects/' . $this->slug . "/");
    }
  
    /**
     * Returns the docs directory path of the generated project
     *
     * That directory is used to put documentation about generated project
     *
     * @return string
     */
    public function docs_path()
    {
        return ($this->base_path() . "docs/");
    }

    /**
     * Returns the url of the docs directory of the generated project
     *
     * @return string
     */
    public function docs_url()
    {
        return ($this->base_url() . "docs/");
    }

    /**
     * Returns the application directory path of the generated project
     *
     * @return string
     */
    public function app_path()
    {
        return ($this->base_path() . "application/");
    }
  
    /**
     * Returns the path of config directory the in generated's project files
     *
     * @return string
     */
    public function config_path()
    {
        return ($this->app_path() . "config/");
    }
  
    /**
     * Returns the path of controllers directory in the generated's project files
     *
     * @return string
     */
    public function controllers_path()
    {
        return ($this->app_path() . "controllers/");
    }
  
    /**
     * Returns the path of models directory in the generated's project files
     *
     * @return string
     */
    public function models_path()
    {
        return ($this->app_path() . "models/");
    }

    /**
     * Returns the path of the views directory in generated's project files
     *
     * @return string
     */
    public function views_path()
    {
        return ($this->app_path() . "views/");
    }

    public function viewsTemplatesPath()
    {
        return $this->views_path() . 'templates/';
    }

    public function modelFilePath()
    {
        return $this->models_path() . $this->slug . '_model.php';
    }

    public function controllerFilePath()
    {
        return $this->controllers_path() . 'protoweb/' . $this->slug . '.php';
    }

    public function generateEntityModels($generateCustom)
    {
        foreach ($this->entity as $entity) {
            $entity->generateModelFiles($generateCustom);
        }
    }

    public function compileAllViews()
    {
        foreach ($this->entity as $entity) {
            $entity->compileAllViews();
        }
    }

} // Class Project

/* End of file project.php */
/* Location: ./application/models/project.php */
